####
rm(list = ls())
library(ctgt)
library(faux)


## size
n = 100

# binary response
y = rbinom(n,1,0.6)


## big design matrix with max 200 features
m = 200
varnames = paste("x", sep = "", 1:m)
nrep = 10
ACtime = matrix(NA,nrep,m/2)
for(s in 1:nrep){
  set.seed(1234 + s)
  X = as.matrix(rnorm_multi(n = n, vars = m, mu = 0, sd = 1, r = 0.5, varnames = varnames) )
  ## first half features are true
  X[which(y==1),1:(m/2)] = X[which(y==1),1:(m/2)] + 0.5
  
  ## features
  vset = seq.int(2,m,2)
  v = length(vset)
  ACT = rep(0,v)
  for( i in 1:v){
    hyps = varnames[1:i]
    xs = varnames[c(1:i, (m/2+1):(m/2 +i) ) ]
    actt = c()
    for(r in 1:10){
      act_time = system.time( {act = actgt(y = y, X = X[,xs], xs = xs, hyps = hyps, maxit = 50000)} )
      actt[r] = act_time[1]
      if(act[1]=="unsure"){
        print("increase maxit")
        print(s)
        print(i)
      }
      if(act_time[1] > 300) break
    }
    ACT[i] = median(actt)
    if(ACT[i] > 3600) break
  }
  
  ACtime[s,] =  ACT
}


ACtime

save(ACtime, file = "ACT.RData")


